﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using ERP_RORZE_DLL.Product.DAO;
using ERP_RORZE_DLL.Product.database;

namespace ERP_RORZE_PRODUCT.Product.WTS
{
    public partial class ctrlLaborWTSDetail : DevExpress.XtraEditors.XtraUserControl
    {
        DataTable dt;
        ClsWTSDAO clsWTSDAO = new ClsWTSDAO();
        ClsLaborWTSTable b = new ClsLaborWTSTable();

        public ctrlLaborWTSDetail()
        {
            InitializeComponent();
            gridView1.BestFitColumns();
        }
        void Reload(object sender, EventArgs e)
        {
            dt = clsWTSDAO.GetAllLaborWTS();
            gridControl1.DataSource = dt;
            gridView1.BestFitColumns();
        }
        private void btnAddNew_Click(object sender, EventArgs e)
        {
            frm_LaborWTSInput frmAdd = new frm_LaborWTSInput();
            frmAdd.Reload += new EventHandler(Reload);
            frmAdd.ShowDialog();
        }

        private void btEdit_Click(object sender, EventArgs e)
        {
            frm_LaborWTSEdit frmEdit = new frm_LaborWTSEdit();
            frmEdit.Reload += new EventHandler(Reload);
            frmEdit.ID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString();
            frmEdit.ClampTime = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Clamptime").ToString();
            frmEdit.Date = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "date").ToString();
            frmEdit.MachineID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MachineID").ToString();
            frmEdit.MONo = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MONo").ToString();
            frmEdit.NGQty = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGQty").ToString();
            frmEdit.Note1 = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note1").ToString();
            frmEdit.Note2 = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Note2").ToString();
            frmEdit.OKQty = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OKQty").ToString();
            frmEdit.OptionID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "OptionID").ToString();
            frmEdit.ProTime = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ProTime").ToString();
            frmEdit.Shift = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "Shift").ToString();
            frmEdit.StaffID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "StaffID").ToString();
            frmEdit.Time = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "time").ToString();
            frmEdit.WorkID = gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "WorkID").ToString();
            frmEdit.ShowDialog();
        }

        private void btnWTStoGA_Click(object sender, EventArgs e)
        {
            frm_LaborWTStoGA frmToGA = new frm_LaborWTStoGA();
            frmToGA.ShowDialog();
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            btEdit_Click(sender, e);
        }

        private void ctrlLaborWTSDetail_Load(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnReload_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnRefresh_Click(object sender, EventArgs e)
        {
            Reload(sender, e);
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            b.ID = int.Parse(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString());
            clsWTSDAO.DeleteLaborWTS(b);
            Reload(sender, e);
        }

        private void btDelete_Click(object sender, EventArgs e)
        {
            btnDelete_Click(sender, e);
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            btnAddNew_Click(sender, e);
        }
    }
}
